Repository navigation
refactor: simplify api helpers, Algolia hooks, error handling and feed paging, and drop low-value tests - #353
Merged
Merged
Conversation
- Drop the unused Tooltip wrapper and its provider. - Merge the best/new/show/ask ranked-list fetchers into one fetchRankedStories with a single ids cache. - Use signal.throwIfAborted(), isHiringThread() and the story normalizer instead of inline copies. - Define the feed types once (FEED_TYPES) and reuse feedCache's isStale instead of a second 5-minute check. - Trim unused barrel re-exports and fix the two circular imports through components/index.ts. - Delete the unused CachedItem and CachedFeed types.
useDomainInfiniteStories and useUserInfiniteStories were two copies of the same paging, dedup, cache and staleness logic. Both now wrap useAlgoliaInfiniteStories and only supply the query, the domain host filter and the domain cold-start cap. DomainStories, UserSubmissions and UserProfile are now keyed by their route param in App.tsx, like the swipe viewers already were, so a new domain or user remounts the page. That replaces the render-time state resets and layout-effect ref resets in the three hooks. Tests that rerendered one hook instance with a new key are replaced by a remount test, and a new e2e test pins the profile key.
…y search - Remove InfiniteStoryListPage's resetKey and the reset branch in useStaggerCascadeSlots. The list pages are keyed by feed, domain and user, each equal to the resetKey they passed, so a new context remounts the list and the reset could no longer run. - Replace CommentDetailSkeleton and FullScreenCommentSkeleton, which differed only in their bottom margin, with one CommentArticleSkeleton that takes CommentArticle's articleClassName. - Merge fetchFrontPageForDay and fetchTaggedStoriesForDay into one Algolia day search. excludeTitles only ever got the hiring titles, so it becomes excludeHiring and uses isHiringThread.
Pins loadMore behavior the next commit refactors: the top feed's walk back through earlier days and its 5-empty-day limit, resuming a saved top session on the next earlier day, and best/newest stopping at the end of their list.
The seen-story filter was written five times, the first-page cache refresh and the keep-or-append list update three times, and the day-by-day Algolia loop twice. loadMore now uses takeUnseen, showStories, loadRankedPage and loadDays, and each feed branch is a few lines. The corrupt-session check is computed once. The feed branches, the phase and position model and the saved session format are unchanged, so sessions saved before this still restore.
Remove 187 unit tests and 30 e2e tests that duplicate a remaining test, restate the implementation, test library behavior, or cannot fail (only `not.toThrow`, or only assert fixture data). Coverage moves by 0.1% at most; the lines no longer run had no assertions on them. Also remove two things only those tests used: the unused `__getUserStoriesCacheForTests` export, and the combined `loading` field of `useItemWithComments`, which no component reads.
therealsama
enabled auto-merge
November 27, 2026 21:41
kplachkov
approved these changes
Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes dead and duplicated code, and tests that can't catch a bug, with no user-visible change: 94 files, +800 / −3,853. Each commit covers one area, so it's easiest to review commit by commit.
Changes
fetchBestStoriesandfetchNewStoriesshare onefetchRankedStoriesand one cache.FEED_TYPESis now the only list of feeds. Deleted the unusedTooltipand the barrel exports that nothing imported, which also ends the barrel's circular imports.useAlgoliaInfiniteStories.DomainStories,UserSubmissionsandUserProfileremount via a Reactkeywhen their route param changes, instead of resetting state during render.errorMessageandisAbortErrorinutils/errors.tsreplace 19 hand-written checks.useItemWithCommentshandles every comment load through one success handler and one error handler, instead of four copies of each.SwipeStoryViewerreuses one skeleton, one state view and one hide/show handler pair.InfiniteStoryListPagedropsresetKey, which the route keys made dead. OneCommentArticleSkeletonreplaces two identical skeletons. One Algolia day search replaces two;excludeTitlesbecomesexcludeHiring.loadMore(a34deb5, 24aeb88): new tests pin the top feed's day paging, session resume and list end. ThenloadMoreuses four small helpers instead of five copies of the dedupe filter, three of the cache refresh and two of the day loop (−105 lines).not.toThrow). Also removesuseItemWithComments' combinedloadingfield, which nothing reads.Worth a close look
keyinApp.tsxwould bring back stale pages. The profile, domain and submissions switch tests catch that.loadMorekeeps its feed branches and saved-session format, so sessions saved before this still restore. The new tests pass both before and after the refactor.Validation
npm run typechecknpm run lintnpm run test:runloadMoretests)npm run buildnpm run e2e(all 4 projects)